package com.shop.user.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.entity.pojo.*;
import com.shop.user.mapper.*;
import com.shop.user.service.StyleService;
import com.shop.utils.common.enums.Message;
import com.shop.utils.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Service

public class StyleServiceImpl extends ServiceImpl<StyleMapper,Style> implements StyleService {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private StyleMapper styleMapper;
    @Override
    public Result<List<Style>> waresDetail(Long waresId){
        String k=Message.WeChat_Key_Wares+waresId;
        List<Style> check = (List<Style>) redisTemplate.opsForValue().get(k);
        if (check!=null&&check.size()> Message.Check_Int_Null) {
            return Result.okResult(check);
        }
        List<Style> v = styleMapper.selectList(Wrappers.<Style>lambdaQuery()
                .eq(Style::getWaresId, waresId)
                .eq(Style::getState,Message.Put));
        redisTemplate.opsForValue().set(k,v,1, TimeUnit.HOURS);
        return Result.okResult(v);
    }
}
